using Microsoft.Expression.Drawing.Core;
using System;
using System.Collections.Generic;
using System.Windows;
using System.Windows.Media;
using System.Windows.Shapes;
namespace Microsoft.Expression.Controls
{
	internal class PolylineStrategy : ShapeStrategy
	{
		private PointCollection oldPoints;
		private Polyline sourcePolyline;
		private static readonly DependencyProperty PointsListenerProperty = DependencyProperty.Register("PointsListener", typeof(PointCollection), typeof(PolylineStrategy), new PropertyMetadata(new PropertyChangedCallback(GeometryStrategy.LayoutPropertyChanged)));
		private PointCollection PointsListener
		{
			get
			{
				return (PointCollection)base.GetValue(PolylineStrategy.PointsListenerProperty);
			}
			set
			{
				base.SetValue(PolylineStrategy.PointsListenerProperty, value);
			}
		}
		public PolylineStrategy(LayoutPath layoutPath) : base(layoutPath)
		{
			this.sourcePolyline = (Polyline)layoutPath.SourceElement;
			base.SetListenerBinding(PolylineStrategy.PointsListenerProperty, "Points");
		}
		public override bool HasGeometryChanged()
		{
			return base.HasGeometryChanged() || !PolylineStrategy.PointCollectionsEqual(this.oldPoints, this.sourcePolyline.get_Points());
		}
		protected override PathGeometry UpdateGeometry()
		{
			this.oldPoints = PolylineStrategy.ClonePointCollection(this.sourcePolyline.get_Points());
			return PolylineStrategy.CreatePolylinePathGeometry(this.oldPoints, false);
		}
		public static PointCollection ClonePointCollection(PointCollection points)
		{
			if (points == null)
			{
				return null;
			}
			PointCollection pointCollection = new PointCollection();
			using (IEnumerator<Point> enumerator = points.GetEnumerator())
			{
				while (enumerator.MoveNext())
				{
					Point current = enumerator.get_Current();
					pointCollection.Add(current);
				}
			}
			return pointCollection;
		}
		public static bool PointCollectionsEqual(PointCollection collectionOne, PointCollection collectionTwo)
		{
			if (collectionOne == collectionTwo)
			{
				return true;
			}
			if (collectionOne == null || collectionTwo == null)
			{
				return false;
			}
			if (collectionOne.get_Count() != collectionTwo.get_Count())
			{
				return false;
			}
			for (int i = 0; i < collectionOne.get_Count(); i++)
			{
				if (collectionOne.get_Item(i) != collectionTwo.get_Item(i))
				{
					return false;
				}
			}
			return true;
		}
		public static PathGeometry CreatePolylinePathGeometry(PointCollection points, bool isClosed)
		{
			if (points != null && points.get_Count() != 0)
			{
				PathSegmentCollection pathSegmentCollection = new PathSegmentCollection();
				if (points.get_Count() > 1)
				{
					pathSegmentCollection.Add(PathSegmentHelper.CreatePolylineSegment(points, 1, points.get_Count() - 1, false));
				}
				PathGeometry pathGeometry = new PathGeometry();
				PathGeometry arg_66_0 = pathGeometry;
				PathFigureCollection pathFigureCollection = new PathFigureCollection();
				PresentationFrameworkCollection<PathFigure> arg_60_0 = pathFigureCollection;
				PathFigure pathFigure = new PathFigure();
				pathFigure.set_StartPoint(points.get_Item(0));
				pathFigure.set_IsClosed(isClosed);
				pathFigure.set_Segments(pathSegmentCollection);
				arg_60_0.Add(pathFigure);
				arg_66_0.set_Figures(pathFigureCollection);
				return pathGeometry;
			}
			return new PathGeometry();
		}
	}
}
